package com.hsylient.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

@WebServlet(name = "cookieAcceptServlet", value = "/accept-servlet")
public class CookieAcceptServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.printf("%s:%s%n", cookie.getName(),
                    URLDecoder.decode(cookie.getValue(), StandardCharsets.UTF_8));
        }
    }

    public void destroy() {
    }
}